//
//  LHYMainabBarController.m
//  rabbit微博
//
//  Created by mac on 15/12/13.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "LHYMainabBarController.h"
#import "MainTabBar.h"
#import "LHYHomeTableViewController.h"
#import "LHYMessageTableViewController.h"
#import "LHYDiscoverTableViewController.h"
#import "LHYProfileTableViewController.h"

@implementation LHYMainabBarController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //创建一个TabBar
    MainTabBar *btn = [[MainTabBar alloc] init];
    
    //利用运行时赋值，加上这句话 加号按钮才会显示
    [self setValue:btn forKey:@"tabBar"];
    
    //加号按钮点击事件
    [btn.plusBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    
    //添加TabBar
    [self addTabBar];
}


- (void)addTabBar
{
    [self addChildViewControllers:[[LHYHomeTableViewController alloc] init] andWithTitle:@"首页" andWithImageName:@"tabbar_home"];
    
    [self addChildViewControllers:[[LHYMessageTableViewController alloc] init] andWithTitle:@"消息" andWithImageName:@"tabbar_message_center"];
    
    [self addChildViewControllers:[[LHYDiscoverTableViewController alloc] init] andWithTitle:@"发现" andWithImageName:@"tabbar_discover"];
    
    [self addChildViewControllers:[[LHYProfileTableViewController alloc] init] andWithTitle:@"我" andWithImageName:@"tabbar_profile"];

}

- (void)addChildViewControllers:(UIViewController *)vc andWithTitle:(NSString *)title andWithImageName:(NSString *)imageName
{

    //创建控制器
    UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:vc];
    
    //界面的标题
    vc.title = title;
    
    //tabBar的图片
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    
    //添加自控制器
    [self addChildViewController:nav];

}


- (void)btnClick
{
    NSLog(@"点击了我");
}

@end
